package com.yhl.vocation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhl.vocation.entity.pojo.Student;
import com.yhl.vocation.service.StudentService;
import com.yhl.vocation.mapper.StudentMapper;
import org.springframework.stereotype.Service;

/**
*
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student>
implements StudentService{

    @Override
    public Student getInfo(String openId) {
        Student student = getBaseMapper().selectOne(new LambdaQueryWrapper<Student>().eq(Student::getOpenId, openId));
        if (student != null) {
            return student;
        }
        return null;
    }

    @Override
    public boolean bind(String studentNum, String idCard, String openid) {
        Student student = getBaseMapper().selectOne(new LambdaQueryWrapper<Student>().eq(Student::getStudentNum, studentNum).eq(Student::getIdCard, idCard));
        if (student != null){
            student.setOpenId(openid);
            getBaseMapper().updateById(student);
            return true;
        }
        return false;
    }
}
